#! -*- coding:utf-8 -*-
import logging
from django.core.management.base import BaseCommand

from async import async_job
from common.order.db import get_orders_by_channel
from common.order import db as order_db

_LOGGER = logging.getLogger(__name__)

# 商品名	业务订单号	订单金额
sss = '''CH20180811154359	1647091439025681408	100
CH20180811154347	1647091425610193920	100
CH20180811154345	1647091423287492608	160
CH20180811154320	1647091397229427712	160
CH20180811154258	1647091373813671936	400
CH20180811154252	1647091366906670080	100
CH20180811154204	1647091315252687872	120
CH20180811154151	1647091301623388160	400
CH20180811154140	1647091289545886720	100
CH20180811154131	1647091279531980800	100
CH20180811154104	1647091251153311744	1000
CH20180811154101	1647091247737049088	100
CH20180811154023	1647091206780708864	1000
CH20180811154014	1647091197445233664	2100
CH20180811153920	1647091139145466880	100
CH20180811153902	1647091119544360960	100
CH20180811153856	1647091113338920960	700
CH20180811153839	1647091095185964032	500
CH20180811153825	1647091079889311744	300
CH20180811153742	1647091033949173760	100
CH20180811153742	1647091034086462464	500
CH20180811153655	1647090983538804736	160
CH20180811153638	1647090965110074368	100
CH20180811153614	1647090939554172928	1000
CH20180811153612	1647090937062755328	100
CH20180811153545	1647090908279335936	400
CH20180811153539	1647090902410477568	100
CH20180811153534	1647090896431473664	500
CH20180811153529	1647090890714635264	2000
CH20180811153517	1647090878609870848	1000
CH20180811153415	1647090811848068096	169
CH20180811153342	1647090776081132544	100
CH20180811153336	1647090769996241920	1000
CH20180811153332	1647090765481129984	100
CH20180811153257	1647090728212715520	400
CH20180811153240	1647090709826907136	100
CH20180811153241	1647090710474856448	300
CH20180811153231	1647090700280597504	200'''


class Command(BaseCommand):

    def handle(self, **options):
        print('start')
        for s in sss.splitlines():
            print(s)
            a = s.split('\t')
            pay_id = a[1]
            total_fee = a[2]
            trade_no = a[0]
            extend = {
                'trade_status': '200',
                'trade_no': trade_no,
                'total_fee': total_fee
            }

            order_db.add_pay_success(6001011, pay_id, total_fee, trade_no, extend)
            # async notify
            async_job.notify_mch(pay_id)
        print('end')
